﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Mvc;

namespace ProgrammingSchool.Extensions
{
    public static class StringExtensions
    {
        public static T ParseOrSetDefault<T>(this string str, T val)
        {
            try
            {
                val = (T)Convert.ChangeType(str, val.GetType());
            }
            catch
            {
            }
            return val;
        }
    }

    public static class ContentMapperExtensions
    {
        public static string Image(this UrlHelper helper, string fileName)
        {
            var path = string.Format("~/Content/images/{0}", fileName);
            return helper.Content(path);
        }

        public static string Style(this UrlHelper helper, string fileName)
        {
            var path = string.Format("~/Content/css/{0}", fileName);
            return helper.Content(path);
        }

        public static string Script(this UrlHelper helper, string fileName)
        {
            var path = string.Format("~/Scripts/{0}", fileName);
            return helper.Content(path);
        }
    }
}
